package logs

import (
	"github.com/sirupsen/logrus"
	"os"
	"fmt"
	"github.com/rifflock/lfshook"
	"path"
)

func NewLogger() (Log *logrus.Logger) {
	if Log != nil {
		return Log
	}

	logdir := "./var/log/"

	err := os.MkdirAll(logdir, os.ModeDir)
	if err != nil {
		fmt.Println("log dir create fail")
	}

	pathMap := lfshook.PathMap{
		logrus.InfoLevel:  path.Join(logdir + "info.log"),
		logrus.ErrorLevel: path.Join(logdir + "error.log"),
	}
	Log = logrus.New()
	Log.Hooks.Add(lfshook.NewHook(
		pathMap,
		&logrus.TextFormatter{},
	))
	return Log
}
